import axios from 'axios'
// 账单列表相关store
import { createSlice } from '@reduxjs/toolkit';
const billStore = createSlice({
    name: 'billStore',
    initialState: {
        billList: []
    },
    reducers: {
        setBillList(state, action) {
            state.billList = action.payload
        },
        addBill(state, action) {
            state.billList.push(action.payload)
        }
    }
})
export const { setBillList, addBill } = billStore.actions
// 异步获取
export const getBillList = () => {
    return async (dispatch) => {
        let res = await axios.get('http://localhost:8888/ka')
        console.log(res);
        dispatch(setBillList(res.data))
    }
}
// 新增
export const createBill = (data) => {
    return async (dispatch) => {
        console.log(5555);
        const res = await axios.post('http://localhost:8888/ka', data)

        dispatch(addBill(res.data))
    }
}
export default billStore.reducer